package com.zac.coroutine.algorithm.leetcode.strings

/**
 * author zac
 * date 2025/8/7
 *
 */
object FirstUniqChar {
    @JvmStatic
    fun main(args: Array<String>) {
        print(firstUniqChar("asadsadsv"))
    }

    fun firstUniqChar(s: String): Int {
        val map = LinkedHashMap<Char, Int>()
        for (i in 0 until s.length) {
            if (!map.contains(s[i])) {
                map.put(s[i], i)
            } else {
                map.put(s[i], -1)
            }
        }
        val it = map.iterator()
        while (it.hasNext()) {
            val a = it.next()
            if (a.value != -1) {
                return a.value
            }
        }
        return -1
    }


}